import array_obj_pb2

msg = array_obj_pb2.MyMessage()

# 添加元素
msg.numbers.append(1)
msg.numbers.append(2)
msg.numbers.append(3)

# 访问元素
for num in msg.numbers:
    print(num)

# 添加元素
person = array_obj_pb2.Person()
names = ["John", "Mali", "Tom"]
ages = [15, 16, 17]
for i in range(len(names)):
    person.name = names[i]
    person.age = ages[i]
    msg.people.append(person)

# 访问元素
for it in msg.people:
    print(it)

# 序列化
bin_data = msg.SerializeToString()
print(f"len: {len(bin_data)}, data: {bin_data}")

# bin_data = msg.SerializeToBytes()
# print(f"len: {len(bin_data)}, data: {bin_data}")